﻿//Associations enable you to express relationships between different Models.（关联类是站在主-从关系去封装model间的关系的）
Ext.data.Association = Ext.extend(Object, {

    //Association的主键
    primaryKey: 'id',

    constructor: function (config) {
        Ext.apply(this, config);

        var types = Ext.ModelMgr.types,
            ownerName = config.ownerModel,          //主model的注册名
            associatedName = config.associatedModel,//从model的注册名
            ownerModel = types[ownerName],          //主model的类
            associatedModel = types[associatedName],//从model的类
            ownerProto;

        if (ownerModel == undefined) {
            throw new Error("The configured ownerModel was not valid (you tried " + ownerName + ")");
        }

        if (associatedModel == undefined) {
            throw new Error("The configured associatedModel was not valid (you tried " + associatedName + ")");
        }

        //将上面处理的两个Model的名称和类赋给Ext.data.Association对象
        this.ownerModel = ownerModel;
        this.associatedModel = associatedModel;

        Ext.applyIf(this, {
            ownerName: ownerName,
            associatedName: associatedName
        });
    }
});